@extends('backend.layouts.app')

@section('content')
<div class="layui-card">
    <div class="layui-card-header layui-card-header-auto">
        相关联岗位名称: {{$relation->name}}
    </div>
    <div class="layui-card-body">
        <div class="layui-row" style="margin-bottom:10px">
            <div class="layui-col-md9">&nbsp;</div>
            <div class="layui-col-md3">
                <div class="layui-btn-group" style="float:right">
                    <a href="{{route('admin.resume.relation.related.create',['id'=>$relation->relation_id])}}"
                        class="layui-btn layui-btn-sm">添加</a>
                    <a href="{{route('admin.resume.relation.index')}}" class="layui-btn layui-btn-sm">返回</a>
                </div>
            </div>
        </div>
        <table id="dataTable" lay-filter="dataTable"></table>
        <script type="text/html" id="options">
            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</a>
            </div>

        </script>
    </div>
</div>
@endsection

@section('script')
<script type="text/javascript">
    layui.use(['layer', 'table', 'form'], function () {
        let layer = layui.layer;
        let form = layui.form;
        let table = layui.table;

        let dataTable = table.render({
            elem: '#dataTable',
            url: "{{route('admin.resume.relation.related.pageList',['id'=>$relation->relation_id])}}",
            page: true,
            cellMinWidth: 200,
            cols: [
                [{
                    field: 'industry_name',
                    title: '行业名称'
                }, {
                    field: 'station_name',
                    title: '岗位名称'
                }, {
                    fixed: 'right',
                    align: 'center',
                    toolbar: '#options'
                }]
            ]
        });

        table.on('tool(dataTable)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;
            switch (layEvent) {
                case 'del':
                    layer.confirm('确认删除吗？', function (index) {
                        $.post("{{ route('admin.resume.relation.related.destroy') }}", {
                                '_method': 'delete',
                                '_token': '{{csrf_token()}}',
                                data: data
                            },
                            function (result) {
                                if (result.code == 0) {
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg);
                            }
                        );
                    });
                    break;
            }
        })
    });

</script>
@endsection
